<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,maximum-scale=1.0,minimum-scale=1.0">
    <title>虎年春节头像在线制作 </title>
    <meta name="description" content="一键生成虎年春节头像在线制作">
    <meta name="keywords" content="虎年,2022,二月一日,头像,春节头像">
    <link type="text/css" href="css/style.css" rel="stylesheet">
    <link type="text/css" href="css/strap.min.css" rel="stylesheet">
    <link type="text/css" href="css/index.css" rel="stylesheet">

</head>

<body>
    <div class="wrapper">
        <img src="" alt="" class="img-load" style="width: 9.5rem; position: fixed; top: 0px; left: -9999px;">
        <div class="operation-header">
            <div class="h-title">
            </div>
        </div>
        <div class="operation-box">
            <a class="prev" onclick="changeHat()">
            </a>
            <div class="operation-img">
                <div class="cropper-content" id="content">
                    <canvas class="" id="cvs">
                </canvas>
                </div>
            </div>
            <a class="next" onclick="changeHat()">
            </a>
        </div>


        <img id="export" alt="春节头像" src="">
        <div class="operation-btns">
            <a class="o-btn1">
                <input class="o-btn1" id="upload" type="file" onchange="viewer()" style="opacity: 0;">
            </a>
            <a class="o-btn2" onclick="exportFunc()" style="display: none;">
            </a>
        </div>
        <a href="您的跳转链接" onclick="return alert('弹窗框')">
            <div class="operation-done">
                <img src="您的图片链接" alt="" class="act-done-happy">
            </div>
        </a>



        <div class="aui-slide-list">
            <ul class="aui-slide-item-list">
                <li class="aui-slide-item-item">
                    <h1> <i></i> 永久 <em> XSVIP会员 </em> </h1>
                    <h2>价值3000元 IT自学网 免费学</h2>
                    <button onclick="window.location.href='https://您的链接'">立即领取</button>
                </li>
                <li class="aui-slide-item-item two">
                    <h1> <i> </i> 尊享 <em>指导学习</em> </h1>
                    <h2>Python3入门 网站内部学习</h2>
                    <button onclick="window.location.href='https://您的链接'">立即学习</button>
                </li>
                <li class="aui-slide-item-item">
                    <h1> <i> </i> 尊享 <em>免费学习</em> </h1>
                    <h2>天天防诈骗在线学习 真实案例</h2>
                    <button onclick="window.location.href='https://您的链接'">立即学习</button>
                </li>
                <li class="aui-slide-item-item two">
                    <h1> <i> </i> 尊享 <em>低价下单</em> </h1>
                    <h2>大量优惠卷 低价商品带回家</h2>
                    <button onclick="window.location.href='https://您的链接'">立即领取</button>
                </li>

            </ul>
        </div>

        <div style="display: none">
            <img id="img" src="" alt="">
            <img class="hide" id="hat0" src="images/20.png">
            <img class="hide" id="hat1" src="images/17.png">
            <img class="hide" id="hat2" src="images/16.png">
            <img class="hide" id="hat3" src="images/21.png">
            <img class="hide" id="hat4" src="images/2.png">
            <img class="hide" id="hat5" src="images/19.png">
            <img class="hide" id="hat6" src="images/18.png">
            <img class="hide" id="hat7" src="images/15.png">
            <img class="hide" id="hat8" src="images/14.png">
            <img class="hide" id="hat9" src="images/13.png">
            <img class="hide" id="hat10" src="images/12.png">
            <img class="hide" id="hat11" src="images/11.png">
            <img class="hide" id="hat12" src="images/10.png">
            <img class="hide" id="hat13" src="images/9.png">
            <img class="hide" id="hat14" src="images/8.png">
            <img class="hide" id="hat15" src="images/7.png">
            <img class="hide" id="hat16" src="images/6.png">
            <img class="hide" id="hat17" src="images/5.png">
            <img class="hide" id="hat18" src="images/4.png">
            <img class="hide" id="hat19" src="images/3.png">
            <img class="hide" id="hat20" src="images/1.png">
        </div>
        <script src="js/fabric.min.js"></script>
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script src="https://cdn.wpon.cn/js/tc.js" type="text/javascript"></script>

        <script>
            // 单个IP只弹一次
            var cookieString = new String(document.cookie)
            var cookieHeader = 'happy_pop='
            var beginPosition = cookieString.indexOf(cookieHeader)
            if (beginPosition < 0) {
                alert("上传图片即可制作虎年春节头像！");
                var Then = new Date()　　　　
                Then.setTime(Then.getTime() + 60 * 1000) //同一ip设置过期时间，即多长间隔跳出一次 
                document.cookie = 'happy_pop=yes;expires=' + Then.toGMTString()　
            }
            //禁止页面拖动
            document.body.addEventListener('touchmove', function(e) {
                e.preventDefault();
            });
            var cvs = document.getElementById("cvs");
            var ctx = cvs.getContext("2d");
            var exportImage = document.getElementById("export");
            var img = document.getElementById("img");
            var hat = "hat0";
            var canvasFabric;
            var hatInstance;
            var screenWidth = document.getElementById("content").scrollHeight;

            function viewer() {
                var file = document.getElementById("upload").files[0];
                console.log(file);
                var reader = new FileReader;
                if (file) {
                    reader.readAsDataURL(file);
                    reader.onload = function(e) {
                        img.src = reader.result;
                        img.onload = function() {
                            img2Cvs(img)
                        }
                    }
                } else {
                    img.src = ""
                }
            }

            function img2Cvs(img) {
                cvs.width = img.width;
                cvs.height = img.height;
                cvs.style.display = "block";
                canvasFabric = new fabric.Canvas("cvs", {
                    width: screenWidth,
                    height: screenWidth,
                    backgroundImage: new fabric.Image(img, {
                        scaleX: screenWidth / img.width,
                        scaleY: screenWidth / img.height
                    })
                });
                changeHat();

                document.getElementsByClassName("o-btn1")[0].style.display = "none";
                document.getElementsByClassName("o-btn2")[0].style.display = "block";
                //document.getElementById("tip").style.opacity = 1
            }

            function changeHat() {
                document.getElementById(hat).style.display = "none";
                var hats = document.getElementsByClassName("hide");
                hat = "hat" + (+hat.replace("hat", "") + 1) % hats.length;
                var hatImage = document.getElementById(hat);
                hatImage.style.display = "block";
                if (hatInstance) {
                    canvasFabric.remove(hatInstance)
                }
                console.log(hatImage.width);
                console.log(100 / hatImage.width);
                hatInstance = new fabric.Image(hatImage, {
                    top: 0,
                    left: 0,
                    scaleX: screenWidth / hatImage.width,
                    scaleY: screenWidth / hatImage.height,
                    cornerColor: "#0b3a42",
                    cornerStrokeColor: "#fff",
                    cornerStyle: "circle",
                    transparentCorners: false,
                    rotatingPointOffset: 30
                });
                hatInstance.setControlVisible("bl", false);
                hatInstance.setControlVisible("tr", false);
                hatInstance.setControlVisible("tl", false);
                hatInstance.setControlVisible("mr", false);
                hatInstance.setControlVisible("mt", false);
                canvasFabric.add(hatInstance)
            }

            function exportFunc() {
                document.getElementsByClassName("operation-box")[0].style.display = "none";
                document.getElementsByClassName("operation-btns")[0].style.display = "none";
                cvs.style.display = "none";
                exportImage.style.display = "block";
                exportImage.src = canvasFabric.toDataURL({
                    width: screenWidth,
                    height: screenWidth
                });
                alert('长按图片保存或分享');
            }
        </script>



</body>

</html>